home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / multinh2.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  2KB  |  82 lines

  1.                                   // Chapter 9 - Program 2
  2. #include <iostream.h>
  3.  
  4. class moving_van {
  5. protected:
  6.    float payload;
  7.    float gross_weight;
  8.    float mpg;
  9. public:
  10.    void initialize(float pl, float gw, float in_mpg) {
  11.         payload = pl;
  12.         gross_weight = gw;
  13.         mpg = in_mpg; };
  14.    float efficiency(void) {
  15.         return(payload / (payload + gross_weight)); };
  16.    float cost_per_ton(float fuel_cost) {
  17.         return(fuel_cost / (payload / 2000.0)); };
  18.    float cost_per_full_day(float cost_of_gas) {
  19.         return(8.0 * cost_of_gas * 55.0 / mpg); };
  20. };
  21.  
  22.  
  23. class driver {
  24. protected:
  25.    float hourly_pay;
  26. public:
  27.    void initialize(float pay) {hourly_pay = pay; };
  28.    float cost_per_mile(void) {return(hourly_pay / 55.0); } ;
  29.    float cost_per_full_day(float overtime_premium) {
  30.         return(8.0 * hourly_pay); };
  31. };
  32.  
  33.  
  34. class driven_truck : public moving_van, public driver {
  35. public:
  36.    void initialize_all(float pl, float gw, float in_mpg, float pay)
  37.         { payload = pl;
  38.           gross_weight = gw;
  39.           mpg = in_mpg;
  40.           hourly_pay = pay; };
  41.    float cost_per_full_day(float cost_of_gas) {
  42.           return(8.0 * hourly_pay +
  43.                 8.0 * cost_of_gas * 55.0 / mpg); };
  44. };
  45.  
  46.  
  47. main()
  48. {
  49. driven_truck chuck_ford;
  50.  
  51.    chuck_ford.initialize_all(20000.0, 12000.0, 5.2, 12.50);
  52.  
  53.    cout << "The efficiency of the Ford is " <<
  54.            chuck_ford.efficiency() << "\n";
  55.  
  56.    cout << "The cost per mile for Chuck to drive is " <<
  57.            chuck_ford.cost_per_mile() << "\n";
  58.  
  59.    cout << "The cost per day for the Ford is " <<
  60.            chuck_ford.moving_van::cost_per_full_day(1.129) <<
  61.            "\n";
  62.  
  63.    cout << "The cost of Chuck for a full day is " <<
  64.            chuck_ford.driver::cost_per_full_day(15.75) <<
  65.            "\n";
  66.  
  67.    cout << "The cost of Chuck driving the Ford for a day is " <<
  68.            chuck_ford.driven_truck::cost_per_full_day(1.129) <<
  69.            "\n";
  70. }
  71.  
  72.  
  73.  
  74.  
  75. // Result of execution
  76. //
  77. // The efficiency of the Ford is .625
  78. // The cost per mile for Chuck to drive is 0.227273
  79. // The cost per day for the Ford is 95.530769
  80. // The cost of Chuck for a full day is 100.0
  81. // The cost of Chuck driving the Ford for a day is 195.530762
  82.